package cn.sccl.dirms.topo.discovery.controller;

import cn.sccl.common.model.PageResult;
import cn.sccl.common.web.BaseController;
import cn.sccl.dirms.topo.discovery.model.DiscoverTaskQueue;
import cn.sccl.dirms.topo.discovery.model.DiscoverTaskQueueVO;
import cn.sccl.dirms.topo.discovery.service.DiscoverTaskQueueManager;
import com.fasterxml.jackson.annotation.JsonView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* 自动发现任务队列表 的Controller
* Created by _minus on 2017-09-28.
*/
@RestController
@RequestMapping(value = "/nms/topo/discovery/discoverTaskQueue")
public class DiscoverTaskQueueController extends BaseController {

    @Autowired
    private DiscoverTaskQueueManager discoverTaskQueueManager;

    /**
    * 显示所有数据
    */
    @RequestMapping(value = "/all" , method = RequestMethod.GET)
    public List<DiscoverTaskQueue> listAllDiscoverTaskQueue(){
        return discoverTaskQueueManager.listAll();
    }

    /**
    * 分页查询，分页参数放置在url路径中
    * @param pageIndex 页码
    * @param pageSize 分页大小
    * @param request
    * @return
    */
    @RequestMapping(value = "/page/{pageIndex}/{pageSize}" , method = RequestMethod.GET)
    public PageResult<DiscoverTaskQueue> pageQueryDiscoverTaskQueue(@PathVariable("pageIndex") long pageIndex , @PathVariable("pageSize") int pageSize , HttpServletRequest request){
        return discoverTaskQueueManager.pageQueryByLike(pageIndex, pageSize, getQueryData(request));
    }


    //    获取当前topo 图中的任务队列中的任务列表

    @RequestMapping(value = "/list/by/graph/{id}" , method = RequestMethod.GET)
    public List<DiscoverTaskQueueVO> queryDiscoverTaskQueueVOByGraphId(@PathVariable("id") String id){
        return discoverTaskQueueManager.queryDiscoverTaskQueueVOByGraphId(id);
    }

    /**
    * 分页查询，分页参数放置在request中
    * @param request
    * @return
    */
    @RequestMapping(value = "/page" , method = RequestMethod.GET )
    public PageResult<DiscoverTaskQueue> pageQueryDiscoverTaskQueue(HttpServletRequest request){
        return discoverTaskQueueManager.pageQueryByLike(getPageIndex(request), getPageSize(request), getQueryData(request));
    }

    /**
    * 保存数据
    * @param discoverTaskQueue
    * @return
    */
    @RequestMapping(value = "/" , method = RequestMethod.POST)
    public DiscoverTaskQueue saveDiscoverTaskQueue(@RequestBody DiscoverTaskQueue discoverTaskQueue){
        discoverTaskQueueManager.save(discoverTaskQueue);
        return discoverTaskQueue;
    }

    /**
    * 根据ID删除数据
    * @param id
    */
    @RequestMapping(value = "/{id}" , method = RequestMethod.DELETE)
    @JsonView(Object.class)
    public void deleteDiscoverTaskQueue(@PathVariable("id") String id){
        discoverTaskQueueManager.delete(id);
    }
}
